package com.newtouch.bxzs.enterprise.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.newtouch.bxzs.common.base.BaseErrorEnum;
import com.newtouch.bxzs.common.base.BaseException;
import com.newtouch.bxzs.common.base.em.SystemParamsEnum;
import com.newtouch.bxzs.common.base.util.RedisUtils;
import com.newtouch.bxzs.common.base.util.SendHttpRequestUtils;
import com.newtouch.bxzs.enterprise.model.bo.BankCustomerAnalysisBO;
import com.newtouch.bxzs.enterprise.model.bo.InsuranceCustomerAnalysisBO;
import com.newtouch.bxzs.enterprise.model.vo.CustomerAnalysisVO;
import com.newtouch.bxzs.enterprise.service.CustomerAnalysisService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 提供保险/银行调对端查询客户分析信息接口ServiceImpl
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/3/23 10:08</td>
 * <td>dingqianbin</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author dingqianbin
 * @version 1.0.0
 * @since 1.0.0
 */
@Service
public class CustomerAnalysisServiceImpl implements CustomerAnalysisService {

    private static final Log logger = LogFactory.getLog(CustomerAnalysisServiceImpl.class);

    @Autowired
    RedisUtils redisUtils;

    @Override
    public InsuranceCustomerAnalysisBO getInsuranceCustomerAnalysisInfo(CustomerAnalysisVO customerAnalysisVO) {
        SendHttpRequestUtils<CustomerAnalysisVO> sendHttpRequestUtils = new SendHttpRequestUtils<>();
        JSONObject jsonObject = sendHttpRequestUtils.sendHttpRequestToJson(customerAnalysisVO, redisUtils.get(SystemParamsEnum.INSURANCE_CUSTOMER_ANALYSIS_INFO.getCode()));
        if(jsonObject != null) {
            return JSONObject.toJavaObject(jsonObject, InsuranceCustomerAnalysisBO.class);
        }else {
            logger.error("暂无该客户分析信息");
            throw new BaseException(BaseErrorEnum.NO_CUSTOMER_ANALYSIS_INFORMATION);
        }
    }

    @Override
    public BankCustomerAnalysisBO getBankCustomerAnalysisInfo(CustomerAnalysisVO customerAnalysisVO) {
        SendHttpRequestUtils<CustomerAnalysisVO> sendHttpRequestUtils = new SendHttpRequestUtils<>();
        JSONObject jsonObject = sendHttpRequestUtils.sendHttpRequestToJson(customerAnalysisVO, redisUtils.get(SystemParamsEnum.BANK_CUSTOMER_ANALYSIS_INFO.getCode()));
        if(jsonObject != null) {
            return JSONObject.toJavaObject(jsonObject, BankCustomerAnalysisBO.class);
        }else {
            logger.error("暂无该客户分析信息");
            throw new BaseException(BaseErrorEnum.NO_CUSTOMER_ANALYSIS_INFORMATION);
        }
    }
}
